



//《客户端》



#include <sys/types.h>			/* See NOTES */
#include <sys/socket.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>



int main(int argc,char ** argv)
{
	int iSocketClient;
	int iRet;
	struct sockaddr_in iSocketServerAddr;
	unsigned char ucSendBuff[1000];
	int iSendLen;
	if(argc != 3)
	{
		printf("usage :\n");
		printf("%s <server_ip> <str>\n",argv[0]);
	}
//调用socket得到一个句柄	
	iSocketClient = socket(AF_INET,SOCK_DGRAM, 0);
	iSocketServerAddr.sin_family       =AF_INET;
	//把主机的字节序转换成网络字节序
	iSocketServerAddr.sin_port         = htons(8888);
	//将argv[1]字符串，转换存入iSocketServerAddr.sin_addr中
	if(inet_aton(argv[1],&iSocketServerAddr.sin_addr)==0)
	{
		printf("inet_ntoa error invaild server_ip\n");
		return -1;
	}

	//iSocketServerAddr.sin_zero[]数组设置为0，共8个字节
	memset(iSocketServerAddr.sin_zero,0,8);
//用connect就连接到某个服务器上去
	iRet =connect(iSocketClient, ( struct sockaddr *)&iSocketServerAddr, sizeof(struct sockaddr));
	if(iRet == -1)
	{
		printf("connect error\n");
	}


//连接成功后用send发送数据
		iSendLen = send(iSocketClient,argv[2],strlen(argv[2]),0);
		if(iSendLen <=0)
		{
			close(iSocketClient);
			printf("send error\n");

			return -1;
		}







}





















































